﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Back.Xinkui.Entity.Manager;

public partial class UserControls_Manager_LeftMenu : System.Web.UI.UserControl
{
    private List<VMenu> MenuList
    { get; set; }

    private List<VMenuPage> PageList
    { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            MenuList = new List<VMenu> { };
            MenuList.Add(new VMenu { MenuID = 1, MenuName = "供应商管理" });
            MenuList.Add(new VMenu { MenuID = 2, MenuName = "买家管理" });
            MenuList.Add(new VMenu { MenuID = 3, MenuName = "询盘管理" });
            MenuList.Add(new VMenu { MenuID = 4, MenuName = "广告管理" });

            PageList = new List<VMenuPage> { };
            PageList.Add(new VMenuPage { MenuID = 1, PageID = 1, MenuName = "供应商列表", PageUrl = "/company/list.aspx", IsShow = 1 });
            PageList.Add(new VMenuPage { MenuID = 1, PageID = 3, MenuName = "产品列表", PageUrl = "/company/productlist.aspx", IsShow = 1 });

            PageList.Add(new VMenuPage { MenuID = 2, PageID = 2, MenuName = "买家列表", PageUrl = "/company/list.aspx", IsShow = 1, PageParame = "isBuy=1" });

            PageList.Add(new VMenuPage { MenuID = 3, PageID = 1, MenuName = "询盘列表", PageUrl = "/buylead/list.aspx", IsShow = 1 });

            PageList.Add(new VMenuPage { MenuID = 4, PageID = 1, MenuName = "广告位列表", PageUrl = "/advert/advertSpaceList.aspx", IsShow = 1 });

            TreeView1.Nodes.Clear();
            ReLoad(0);
        }
    }

    private void ReLoad(int AppID)
    {
        ComponentArt.Web.UI.TreeViewNode newTopItem;
        ComponentArt.Web.UI.TreeViewNode newSubItem;

        List<VMenu> ListMM = MenuList.Where(u => u.AppID == AppID).OrderByDescending(u => u.OrderBy).ToList();
        List<VMenuPage> ListMMP = null;
        if (ListMM.Count > 0)
        {
            foreach (VMenu vmm in ListMM)
            {
                newTopItem = new ComponentArt.Web.UI.TreeViewNode();
                newTopItem.Text = vmm.MenuName;
                TreeView1.Nodes.Add(newTopItem);
                ListMMP = PageList.Where(u => u.MenuID == vmm.MenuID).OrderByDescending(u => u.OrderBy).ToList();
                foreach (VMenuPage vmmp in ListMMP)
                {
                    if (vmmp.IsShow == 1)
                    {
                        //if (VerifyAuthority.CheckPageAuth(UserID, vmmp.PurviewName))
                        //{
                        newSubItem = new ComponentArt.Web.UI.TreeViewNode();
                        newSubItem.Text = vmmp.MenuName;
                        //if (vmmp.PageUrl.ToLower().IndexOf("http://") < 0)
                        //{
                        //    newSubItem.ClientSideCommand = "iframesrc('http://" + vmmp.Domain + vmmp.PageUrl + "?GasActionPerValue=" + vmmp.PerValue + "&AppID=" + vmmp.Appid.ToString() + "&" + vmmp.PageParame + "')";
                        //    newSubItem.Value = "http://" + vmmp.Domain + vmmp.PageUrl + "?GasActionPerValue=" + vmmp.PerValue + "&AppID=" + vmmp.Appid.ToString() + "&" + vmmp.PageParame;
                        //}
                        //else
                        //{
                        newSubItem.ClientSideCommand = "iframesrc('" + vmmp.PageUrl + "?GasActionPerValue=" + vmmp.PerValue + "&AppID=" + vmmp.Appid.ToString() + "&" + vmmp.PageParame + "')";
                        newSubItem.Value = vmmp.PageUrl + "?GasActionPerValue=" + vmmp.PerValue + "&AppID=" + vmmp.Appid.ToString() + "&" + vmmp.PageParame;
                        //}
                        newTopItem.Nodes.Add(newSubItem);
                        //}
                    }
                }
                if (newTopItem.Nodes.Count == 0)
                {
                    TreeView1.Nodes.Remove(newTopItem);
                }
            }
        }
    }
}